﻿// For more information see https://aka.ms/fsharp-console-apps

//open System
open System
open Microsoft.FSharp.Core

printfn "Hello from F#"
//string aStr
//不能这样写、、要let
//String aStr
//aStr="a"
let aStr="a"

//stri
let sample = Map [ (1, "a"); (2, "b") ]
//let mutable sample = Map [ (1, "a"); (2, "b") ]
sample.Add(3, "c") // evaluates to map [(1, "a"); (2, "b"); (3, "c")]
sample.Add(2, "aa") // evaluates to map [(1, "a"); (2, "aa")]
//rider 怎么run 部分的f# 代码
//返回了吗 他是不会改变原来的 必须返回出来的接住才行吧  ，确实 rider也提示ignore了， 就和java的string一个道理
//mapTest.fs(5,1): error FS0010: 意外的 结构化构造开始 在定义中。应为 符号“=” 或其他标记。
//sample
sample.Add(1,"2")
let res=sample
printf "sample:\n"
//后面的是类型
//https://docs.microsoft.com/zh-cn/dotnet/fsharp/language-reference/functions/
let printMap (map:Map<int,string>) =
    for key in map.Keys do
        printfn "======"
        printf "key: %d\n" key
        printf "val: %s" map.[key]
        printfn ""
    
//let printMap (map:Map<int,String>) =
//map.
//printf sample
//printfn sample
//Printf sample
//pri
//for sample.Keys printf 
//for KeyValue in sample.Keys
//sample
//for (k,v) in sample.Keys
//https://blog.51cto.com/cnn237111/897213
//但是他好像不会变
//for key in sample.Keys do
//    printfn "======"
//    printf "key: %d\n" key
//    printf "val: %s" sample.[key]
//    printfn ""

//printMap(sample)
//https://fsharp.github.io/fsharp-core-docs/reference/fsharp-collections-fsharpmap-2.html
//String
//https://cloud.tencent.com/developer/ask/sof/1029953
//Truly it is not empty.
//printfn $"""Truly it is {match (String.IsNullOrEmpty "l") with | true -> "" | false -> "not "}empty."""
printfn $"sample {sample}"
//好活 我发现可以直接这样，这才叫语法糖嘛
//sample:
//sample map [(1, a); (2, b)]

//https://rumenz.com/examples/fsharp/fhash-list-fold.html
//从0 开始加
//函数加上括号也好的 可以运行
//let sumList (list) = List.fold (fun acc elem -> acc + elem) 0 list
let sumList (list) = List.fold (fun acc (elem) ->  acc + elem) 0 list
//折叠 就是reduce 差不多吧
//Sum of the elements of list [1; 2; 3; 4; 5; 6; 7; 8; 9; 10] is 55.
printfn "Sum of the elements of list %A is %d." [ 1 .. 10 ] (sumList [ 1 .. 10 ])

// addedList [2; 4; 1; ... ]

let addedList= 2::4:: [ 1 .. 10 ]
printfn $" addedList {addedList}"